{% extends "reviewers/base.html" %}

{% block title %}
  {% if title %}
    {{ title }} - Add-ons for Firefox
  {% else %}
    {{ super() }}
  {% endif %}
{% endblock %}

{% block bodyclass %}{{ super() }} {{ " content-review" if tab == "queue_content_review" else "" }}{% endblock %}

{% block content %}

<ul class="tabnav">
  {% for this, loc, text in queue_tabnav(registry) %}
  <li class="{% if tab==this %}selected{% endif %}"><a href="{{ url('reviewers.%s' % loc) }}">{{ text }}</a></li>
  {% endfor %}
</ul>

<div class="queue-outer">
  <div class="queue-inner">
    <div class="data-grid-content data-grid-top">
    {{ page|paginator }}
    </div>

    {% if tab == 'queue_moderated' %}
      <div id="reviews-flagged">
        <form method="post" class="item">
          <div class="review-saved">
            <button type="submit">Process Reviews</button>
          </div>
          {% csrf_token %}
          {{ reviews_formset.management_form }}
          {% for review in reviews_formset.forms %}
          <div class="review-flagged{%- if not check_review_delete(review.instance) %} disabled{% endif %}">
            <div class="review-flagged-actions">
              {{ review.errors }}
              <strong>Moderation actions:</strong>
              {{ review.id }}
              {{ review.action }}
            </div>
            <h3>
              <a href="{{ review.instance.addon.get_url_path() }}">
                {{ review.instance.addon.name }}</a>
            </h3>
            <p>
            {% trans user=review.instance.user|user_link, date=review.instance.created|date,
                     stars=review.instance.rating|stars, locale=review.instance.body.locale %}
              by {{ user }} on {{ date }}
              {{ stars }}
            {% endtrans %}
            </p>
            <p class="description">{{ review.instance.body|nl2br }}</p>
            <ul class="reviews-flagged-reasons">
              {% for reason in review.instance.ratingflag_set.all() %}
              <li>
              <div>
                {% trans user=reason.user|user_link, date=reason.modified|datetime,
                         reason=flags[reason.flag] %}
                <strong>{{ reason }}</strong>
                <span class="light">Flagged by {{ user }} on {{ date }}</span>
                {% endtrans %}
              </div>
              {{ reason.note }}
              </li>
              {% endfor %}
            </ul>
          </div>
          {% endfor %}
          {% if page.paginator.count == 0 %}
            <div class="no-results">All reviews have been moderated. Good work!</div>
          {% else %}
            <div class="review-saved review-flagged">
              <button type="submit">Process Reviews</button>
            </div>
          {% endif %}
        </form>
      </div>
      {% elif tab == 'queue_decisions' %}
      <table id="held-decision-queue" class="data-grid">
        <thead>
          <tr class="listing-header">
              <th>Type</th>
              <th>Source</th>
              <th>Target</th>
              <th>Action</th>
              <th>Decision Date</th>
          </tr>
        </thead>
        <tbody>
          {% for decision in page.object_list %}
          <tr id="{{ decision.get_reference_id(short=True) }}" class="held-item {{ decision.source.name }}" >
            <td><div class="app-icon ed-sprite-action-target-{{ decision.get_target_display() }}" title="{{ decision.get_target_display() }}"></div></td>
            <td class="decision-source">{{ decision.source }}</td>
            <td>{{ decision.get_target_name() }}</td>
            <td><a href="{{ decision.get_target_review_url() }}">{{ decision.get_action_display() }}</a></td>
            <td>{{ decision.created|datetime }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      {% if page.paginator.count == 0 %}
        <div class="no-results">There are currently no held actions.</div>
      {% endif %}
    {% else %}
      <div id="addon-queue-filter-form">
        <button class="show-hide-toggle">Show/Hide Filter Selections</button>
        <form action="" method="get">
          {{ filter_form }}
          <div class="select-links">
            [<a href='#' class="select-all">select all</a>]
            [<a href='#' class="select-none">select none</a>]
          </div>
          <input type="submit" value="Update Filters">
        </form>
      </div>
      <table id="addon-queue" class="data-grid" data-url="{{ url('reviewers.queue_viewing') }}">
        <thead>
          <tr class="listing-header">
              <th>&nbsp;</th>
              {% for column in table.columns %}
                {% if column.order_by_alias == column.order_by_alias.next %}
                  {% set cls, sprite = '', 'both' %}
                {% elif column.order_by_alias.is_descending %}
                  {% set cls, sprite = 'ordered', 'desc' %}
                {% elif column.order_by_alias.is_ascending %}
                  {% set cls, sprite = 'ordered', 'asc' %}
                {% endif %}
                <th class="{{ cls }}">
                  {% if column.orderable %}
                    <a href="{{ request.get_full_path()|urlparams(sort=column.order_by_alias.next) }}" class="sort-icon ed-sprite-sort-{{ sprite }}">
                      {{ column }}
                    </a>
                  {% else %}
                    {{ column }}
                  {% endif %}
                </th>
              {% endfor %}
          </tr>
        </thead>
        <tbody>
          {% for row in page.object_list %}
          <tr data-addon="{{ row.record.addon_id or row.record.id }}" class="addon-row {{ table.render_flags_classes(row.record) }}" id="addon-{{ row.record.addon_id or row.record.id }}" data-review-log="{{ row.record.review_log_id }}">
            <td><div class="addon-locked"></div></td>
            {% for value in row %}
              <td>{{ value }}</td>
            {% endfor %}
            <td>&nbsp;</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
      {% if page.paginator.count == 0 %}
        <div class="no-results">There are currently no add-ons of this type to review.</div>
      {% endif %}
    {% endif %}
    <div class="data-grid-content data-grid-bottom">
    {{ page|paginator }}
    </div>
  </div>
</div>

<div id="helpfulLinks">
Helpful Links:
<a href="{{ url('devhub.docs', doc_name='policies') }}">Add-on Policy</a>
|
<a href="https://wiki.mozilla.org/Add-ons/Reviewers/Guide">Reviewer's Guide</a>
</div>

<div class="popup" id="popup-notes" data-version-url="{{ url('reviewers.queue_version_notes') }}" data-review-url="{{ url('reviewers.queue_review_text') }}"></div>

{% endblock %}
